#include "cutter.h"

Cutter::Cutter(FacilityDefine *define, FacilityDirection f_dir, Coordinate co,Cargo_Manager * cargo_manager)
    :Facility(define,f_dir,co,cargo_manager){}

bool Cutter::isValid(){
    for(auto c: incargos){
        if(!c || !c->is_Divisble()) return false;
    }
    return true;
}

void Cutter::finishProcess(){
    if(!isValid()) return;
    auto p = cargo_manager->cropShape((ShapeCargo*)incargos[0]);
    if(p.first)cargo_manager->paintShapeCargo(abs_exits[0].position.x,abs_exits[0].position.y,abs_exits[0].direction,p.first);
    if(p.second)cargo_manager->paintShapeCargo(abs_exits[1].position.x,abs_exits[1].position.y,abs_exits[1].direction,p.second);
    outcargos[0] = p.first;
    outcargos[1] = p.second;
    delete incargos[0];
    incargos[0] = null;
    sendCargo();
    Facility::finishProcess();
}
